-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert hashtags to categories/tags when posting #50
base: main
Are you sure you want to change the base?
Conversation
Scan the body for anything that matches a category or tag name that starts with a hashtag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'd be cautious about looping over the categories and terms (what if there are many). What about using regex to extract the tags and then searching for them using the name
parameter of get_terms()
which is used in the background for get_categories()
and get_tags()
.
As this is only done when submitting a post, the overhead hit seems like a reasonable compromise (see below for why). Even if there are a few hundred or thousand terms, that's not a lot of overhead.
Could, but a regex is more challenging as WP allows for terms that have spaces in them, so searching for terms as defined by WP is probably more desirable. Looping through the terms makes catching the tags with spaces easy as we know what we're looking for. |
Interesting, so in your opinion there should be support for specifying a category or tag like this |
Yes
Yes, most users don't know what a slug is, so letting them simply type in "#category name I always see" makes more sense here I think. |
In fact I think there might be an argument to check for three different kinds of tagging; "#this is a tag", "#this-is-a-tag", and "#thisisatag". Aka, replacing spaces with dashes and removing spaces completely and searching for all three in the content. I also think it might make sense to check the last line of the content and see if after tags, there's nothing left and if so, remove it. Both are for future thought though 😁 |
During a post submission, scan the body for anything that matches a category or tag name (case insensitively) that starts with a hashtag and add that to the new post_data array.